package com.xie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xie.domain.Result;
import com.xie.exception.ThisException;
import com.xie.pojo.Dept;
import com.xie.pojo.Manager;
import com.xie.pojo.Medicine;
import com.xie.pojo.Tms;
import com.xie.service.MedicineService;
import com.xie.service.TmsService;
import com.xie.util.MD5Util;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "账单管理")
@RestController
@RequestMapping("/Medicines")
public class MedicineController {
    @Autowired
    private MedicineService medicineService;


    /**
     * 添加账单
     * @param medicine
     * @return
     */

    @PostMapping("/save")
    @ApiOperation("添加账单")
    public Result addSalary(@RequestBody Medicine medicine) {
        System.out.println(medicine);
        boolean save = medicineService.save(medicine);
        if (save) {
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 账单模糊查询
     * @param params
     * @return
     */
    @GetMapping("find/{params}")
    @ApiOperation("模糊查询账单信息")
    public Result FindPage(@PathVariable String params){
        LambdaQueryWrapper<Medicine> lambdaQueryWrapper=new LambdaQueryWrapper();
        lambdaQueryWrapper.like(Medicine::getMedicineId,params)
                .or().like(Medicine::getMedicineName,params)
                .or().like(Medicine::getMedicineNum,params)
                .or().like(Medicine::getMedicinePrice,params)
                .or().like(Medicine::getMedicineQuantity,params)
        ;
        List<Medicine> list = medicineService.list(lambdaQueryWrapper);
        if (list != null) return Result.ok(list);
        return Result.fail();
    }


    /**
     * 删除账单
     * @return
     */
    @DeleteMapping("/remove")
    @ApiOperation("删除账单")
    public Result remove() {
        boolean b = medicineService.remove(null);
        if (b) {
            return Result.ok();
        }
        return Result.fail();
    }


    /**
     * 获取账单
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("获取所有账单")
    public Result exportAdmin(){
        List<Medicine> admin = medicineService.list();
        System.out.println(admin);
        if (admin != null) {
            return Result.ok(admin);
        }
        return Result.fail();
    }

}